package com.five.dao.impl.backstage;

import com.five.dao.backstage.RoleDao;
import com.five.entity.backstage.TRole;
import com.five.util.DBUtil;

import java.util.List;
import java.util.Map;

public class RoleDaoImple implements RoleDao {
    @Override
    public List<Map> queryAll() {
        String sql="select * from t_role";
        List<Map> maps = DBUtil.queryMap(sql);
        return maps;
    }

    @Override
    public int delRole(String id) {
        String sql="delete from t_role where id=?";
        return DBUtil.manage(sql,id);
    }

    @Override
    public int add(TRole role) {
        if(role.getId()==null){
            String sql="insert into t_role(name) values(?)";
            return DBUtil.manage(sql,role.getName());
        }else{
            String sql="update t_role set name=? where id=?";
            return DBUtil.manage(sql,role.getName(),role.getId());
        }
    }

    @Override
    public Map findRoleById(String id) {
        String sql="select * from t_role where id=?";
        List<Map> maps = DBUtil.queryMap(sql, id);
        Map m=maps.get(0);
        return m;
    }


}
